import subprocess
p = input("请输入要检查的网段：")
with open('address.txt','w') as f1:
    for i in range(0,255):
        str = 'ping -c 1 192.168.10.{}'.format(i)
        #shell为True，指定命令将通过shell执行
        a = subprocess.run('ping -c 1 192.168.10.{}'.format(i),shell = True)
        a1 = a.returncode
        print(a1)
        if a1 == 0:
            f1.write(str+"已被使用"+'\n')
 
 f1.close()
